package L1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

/*
考试座位号
 */
public class _005 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        Integer N = Integer.valueOf(reader.readLine());
        Map<String,String[]> map = new HashMap<>();
        while (N>0){
            String[] s = reader.readLine().split(" ");
            String[] data = new String[2];
            data[0]= s[0];
            data[1]= s[2];
            map.put(s[1],data);
            N--;
        }

        Integer M = Integer.valueOf(reader.readLine());
        String[] s = reader.readLine().split(" ");
        for (int i=0;i<M;i++){
            String[] strings = map.get(s[i]);
            System.out.println(strings[0]+" "+strings[1]);
        }
    }
}
